package com.dks.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.dks.models.Course;
import com.dks.repository.ICourseRepository;
import com.dks.result.*;
import com.dks.util.PageInfo;

@RequestMapping("course")
@RestController
public class CourseController {

    private ICourseRepository courseRepository;

    @Autowired
    public CourseController(final ICourseRepository courseRepositoryIn) {
        this.courseRepository = courseRepositoryIn;
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取课程列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-course-list")
    public ResultModel<Object> getCourseList(String courseCategory, Integer pageNum, Integer pageSize, String name) {

        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return courseRepository.getCourseList(courseCategory, pageNum, pageSize, name);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取当前用户单日课程列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: beginTime 开始时间
     * @Param: endTime 结束时间
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-single-day-course-list")
    public ResultModel<Object> getSingleDayCourseList(String beginTime, String endTime, Integer pageNum, Integer pageSize, Integer parentId, Integer studentId, String courseCategory, Integer ageMin, Integer ageMax) {

        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
//        if (null == parentId) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "parentId");
//        }
        return courseRepository.getSingleDayCourseList(beginTime, endTime, pageNum, pageSize, parentId, studentId, courseCategory, ageMin, ageMax);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取当前用户上课记录列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-class-record-list")
    public ResultModel<Object> getClassRecordList(Integer pageNum, Integer pageSize, Integer studentId) {

        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        if (null == studentId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "studentId");
        }
        return courseRepository.getClassRecordList(pageNum, pageSize, studentId);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取推荐课程列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-recommend-course-list")
    public ResultModel<Object> getRecommendCourseList(Integer pageNum, Integer pageSize) {

        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return courseRepository.getRecommendCourseList(pageNum, pageSize);
    }


    /**
     * @Author: Ah Nan
     * @Description: 获取需要签到的课程
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-course-sign-list")
    public ResultModel<Object> getCourseSignList(Integer parentId, String beginTime, String endTime, Integer pageSize, Integer pageNum) {
        if (null == parentId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "parentId");
        }
        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return courseRepository.getCourseSignList(parentId, beginTime, endTime, pageSize, pageNum);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取存在代办事项的课程
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-wait-course-list")
    public ResultModel<Object> getWaitCourseList(Integer parentId) {
        if (null == parentId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "parentId");
        }
        return courseRepository.getWaitCourseList(parentId);
    }


    /**
     * @Author: Ah Nan
     * @Description: 【首页】获取上课提醒列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-attend-course-remind-list")
    public ResultModel<Object> getAttendCoursRemindeList(Integer pageNum, Integer pageSize) {
        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return courseRepository.getAttendCoursRemindeList(pageNum, pageSize);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取待上课课程列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-attend-course-list")
    public ResultModel<Object> getAttendCourseList(Integer parentId) {
        if (null == parentId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "parentId");
        }
        return courseRepository.getAttendCourseList(parentId);
    }


    /**
     * @Author: Ah Nan
     * @Description: 获取是否需要续期提醒
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-renewal-reminder")
    public ResultModel<Object> getRenewalReminder(Integer userId) {
        if (userId == null) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "userId");
        }
        return courseRepository.getRenewalReminder(userId);
    }


    /**
     * @Author: Ah Nan
     * @Description: 获取课程详情
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: courseId 课程id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-course-info")
    public ResultModel<Object> getCourseInfo(Integer courseId) {
        if (null == courseId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "courseId");
        }
        return courseRepository.getCourseInfo(courseId);
    }

//    /**
//     * 查询课程列表: 课程分类 课程分阶 课程名称（模糊）
//     * @author evan
//     */
//    @GetMapping("list")
//    // TODO: 2020/5/7
//    public ResultModel<PageInfo<Course>> getList(String courseName, String courseCategory, String courseStage,
//                                                 Integer pageNum, Integer pageSize) {
//        return courseRepository.getList(courseName, courseCategory, courseStage, pageNum, pageSize);
//    }


    /**
     * @Author: Ah Nan
     * @Description: 获取课程分类
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: name 分类名称
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-course-category")
    public ResultModel<Object> getCourseCategory(String name) {
        return courseRepository.getCourseCategory(name);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取教师所上课程分类列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: name 分类名称
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-teacher-course-category-list")
    public ResultModel<Object> getTeacherCourseCategoryList(Integer teacherId, Integer pageNum, Integer pageSize) {
        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return courseRepository.getTeacherCourseCategoryList(teacherId, pageNum, pageSize);
    }


    /**
     * @Author: Ah Nan
     * @update kenny 修改逻辑
     * @Description: 【首页-学生端】获取待办列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: attendClassStatus 上课状态:0上课,1下课
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-awit-handle-list")
    public ResultModel<Object> getAwitHandleList(Integer pageNum, Integer pageSize, Long userId) {
        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return courseRepository.getAwitHandleList(pageNum, pageSize, userId);
    }

    /**
     * @Author: Ah Nan
     * @Description: 【教务】获取单节课程考勤列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: attendClassStatus 上课状态:0上课,1下课
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-attendance-course-list")
    public ResultModel<Object> getAttendanceCourseList(Integer pageNum, Integer pageSize, Integer classId, String classAttendStatus, String studentName, String parentName) {
        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return courseRepository.getAttendanceCourseList(pageNum, pageSize, classId, classAttendStatus, studentName, parentName);
    }


}
